<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理系统 - 登录</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
        body {
            background-color: #f8f9fa;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-container {
            max-width: 400px;
            width: 100%;
            padding: 30px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .login-logo {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-logo h2 {
            color: #343a40;
        }
        .login-form .input-group-text {
            background-color: #f8f9fa;
            border-right: none;
        }
        .login-form .form-control {
            border-left: none;
        }
        .login-form .btn-primary {
            background-color: #007bff;
            border-color: #007bff;
            width: 100%;
            padding: 10px;
        }
        .login-form .btn-primary:hover {
            background-color: #0069d9;
            border-color: #0062cc;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-logo">
            <h2><i class="fas fa-dumbbell"></i> 体育商城后台</h2>
            <p class="text-muted">管理员登录</p>
        </div>
        <div class="login-form">
            <div id="error-message" class="alert alert-danger d-none" role="alert"></div>
            <form id="login-form">
                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-prepend">
                            <span class="input-group-text"><i class="fas fa-user"></i></span>
                        </div>
                        <input type="text" class="form-control" id="username" name="username" placeholder="用户名" required>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-prepend">
                            <span class="input-group-text"><i class="fas fa-lock"></i></span>
                        </div>
                        <input type="password" class="form-control" id="password" name="password" placeholder="密码" required>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary">登录</button>
                </div>
            </form>
        </div>
    </div>

    <!-- jQuery and Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#login-form').on('submit', function(e) {
                e.preventDefault();
                
                var username = $('#username').val();
                var password = $('#password').val();
                
                // 显示加载
                $('button[type="submit"]').html('<i class="fas fa-spinner fa-spin"></i> 登录中...');
                $('button[type="submit"]').attr('disabled', true);
                
                $.ajax({
                    url: '${pageContext.request.contextPath}/admin/login',
                    type: 'POST',
                    data: {
                        username: username,
                        password: password
                    },
                    success: function(res) {
                        if (res.code === 200 || res.success === true) {
                            // 登录成功，跳转到后台首页
                            window.location.href = '${pageContext.request.contextPath}/admin/index';
                        } else {
                            // 显示错误信息
                            $('#error-message').html(res.message || res.msg).removeClass('d-none');
                            // 恢复按钮状态
                            $('button[type="submit"]').html('登录');
                            $('button[type="submit"]').attr('disabled', false);
                        }
                    },
                    error: function() {
                        $('#error-message').html('服务器错误，请稍后再试').removeClass('d-none');
                        // 恢复按钮状态
                        $('button[type="submit"]').html('登录');
                        $('button[type="submit"]').attr('disabled', false);
                    }
                });
            });
        });
    </script>
</body>
</html> 